import java.util.Scanner;
import java.util.Stack;

/**
 * @author gao
 * @date 2025/9/26 9:03
 */

public class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();

        for (String i : tokens) {
            if (isInteger(i)) {
                stack.push(Integer.parseInt(i));
            } else {
                int num1 = stack.pop();
                int num2 = stack.pop();
                switch (i) {
                    case "+":
                        stack.push(num2 + num1);
                        break;
                    case "-":
                        stack.push(num2 - num1);
                        break;
                    case "*":
                        stack.push(num2 * num1);
                        break;
                    case "/":
                        stack.push(num2 / num1);
                        break;
                }
            }
        }
        return stack.pop();
    }


    public static boolean isInteger(String s) {
        if (s == null) {
            return false;
        }

        return s.matches("-?\\d+");
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            in.nextLine();
            String[] tokens = new String[n];
            for (int i = 0; i < tokens.length; i++) {
                tokens[i] = in.nextLine();
            }
            Solution solution = new Solution();
            System.out.println(solution.evalRPN(tokens));
        }
    }
}